package net.zjitc.controller;

import net.zjitc.domain.Category;
import net.zjitc.domain.CategorySecond;
import net.zjitc.domain.Product;
import net.zjitc.service.Impl.ProductImpl;
import net.zjitc.service.Impl.ServiceImpl;
import net.zjitc.service.ProductService;
import net.zjitc.service.Service;
import utils.PageBean;
import utils.dispacher.URLMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by Administrator on 2017/12/6.
 */
public class UserProduct {
    Service service=new ServiceImpl();
    ProductService productService=new ProductImpl();

    int pageSize=12;
    @URLMapping(url = "/findByCid")
    public String findByCid(HttpServletRequest request, HttpServletResponse response) {
      int page=Integer.valueOf(request.getParameter("page"));
        int cid=Integer.valueOf(request.getParameter("cid"));
        List<Category> list=service.findAllCategory();
        request.setAttribute("clist",list);
        PageBean<Product> pageBean=productService.findPageBeanByCid(page,pageSize,cid);
        request.setAttribute("page",pageBean);
//        System.out.println(pageBean.getPageCount());
//        System.out.println(pageBean.getCount());
        request.setAttribute("cid",cid);
        return "/WEB-INF/user/productList.jsp";
    }
    @URLMapping(url = "/findByCsid")
    public String findByCsid(HttpServletRequest request, HttpServletResponse response) {
        List<CategorySecond> cslist=service.findAllCategorySecond();
        List<Category> clist=service.findAllCategory();
        request.setAttribute("clist",clist);
        request.setAttribute("cslist",cslist);
        int page=Integer.valueOf(request.getParameter("page"));
        int csid=Integer.valueOf(request.getParameter("csid"));
        PageBean<Product> pageBean=productService.findPageByCsid(page,pageSize,csid);
        request.setAttribute("csid",csid);
        request.setAttribute("page",pageBean);
        return "/WEB-INF/user/productList.jsp";
    }
    @URLMapping(url = "/findProductByPid")
    public String findProductByPid(HttpServletRequest request, HttpServletResponse response) {
        int pid = Integer.valueOf(request.getParameter("pid"));
        List<Category> clist=service.findAllCategory();
        request.setAttribute("clist",clist);
        Product product=productService.findProductById(pid);
        request.setAttribute("p",product);
        return "/WEB-INF/user/product.jsp";
    }
}
